<html>
<head>
	<title></title>
</head>
<body>
	<h4></h4>
<?php 
	// 但是elseif可以用于冒号，而else if则不能。
	// elseif和else if在使用大括号的时候是一样的， 
	$price=199;
	if($price > 200){
		echo "$price > 200"; echo "<br/>";
	}else if($price > 100){
		echo "$price > 100"; echo "<br/>";
	} else{
		echo "$price < 10"; echo "<br/>";
	}

	// switch
	echo date("D");
	switch (date("D")) {
		//当前星期作为判断条件
		case "Mon":
			echo "星期一";
			break;
		case "Tue":
			echo "星期二";
			break;
		case "Wed":
			echo "星期三";
			break;
		case "Thu":
			echo "星期四";
			break;
		case "Fri":
			echo "星期五";
			break;
		default:
			echo "过周末";
			break;
	}

	echo "<br/>";
	$i = 0;
	while ($i < 3){
		echo "loop $i";echo "<br/>";
		$i++;
	}


	//首先定义一个数组——图书类型数组
	$type[0][0]="学生用书";
	$type[0][1]="学生教材";
	$type[0][2]="教辅用书";
	$type[0][3]="课外读物";
	$type[0][4]="考试题集";

	$type[1][0]="名著";
	$type[1][1]="中国古典";
	$type[1][2]="世界名著";
	$type[1][3]="英文原著";

	$type[2][0]="考试用书";
	$type[2][1]="公务员";
	$type[2][2]="会计师";
	$type[2][3]="医药师";

	$type[3][0]="儿童读物";
	$type[3][1]="看图识字";
	$type[3][2]="动漫人物";

	$type[4][0]="武侠小说";
	$type[4][1]="金庸小说";
	$type[4][2]="古龙小说";
	$type[4][3]="玄幻小说";
	
	$rowNum =3;
	echo "<table border='1'>";
	// echo "<tr> <td> abc </td></tr>";
	for($i=0, $cata=count($type); $i<$cata; $i++){
		$aType=$type[$i];
		for($j=0, $size=count($aType); $j < $size; $j++){
			$newCata = ($j==0);
			$newRow = ($j%$rowNum==1);
			$rowLast = ($j%$rowNum==0);

			if($newCata){
				echo "<tr bgcolor='#cccc00'>";
				echo "<td  colspan=$rowNum>";
				echo "$aType[$j]";
				echo "</td>";
				echo "</tr>";
			}else if ($newRow){
				echo "<tr bgcolor='#ccccff'>";
				echo "<td>";
				echo "$aType[$j]";
				echo "</td>";
			}else if ($rowLast){
				echo "<td>";
				echo "$aType[$j]";
				echo "</td>";
				echo "</tr>";
			}else{ 
				echo "<td>";
				echo "$aType[$j]";
				echo "</td>";
			}

			// last element but not full a row
			if ($j == $size -1 && !$rowLast){
				$padCnt = $rowNum - ($j%$rowNum);
				for($m=$padCnt; $m>0; $m--){
					echo "<td></td>";
				}
				echo "</tr>";
			} 
		}
	}
	echo "</table>";
?>
<br/>
<a href="/function.php">function in php</a>
</body>
</html>
